package org.zzk.dao;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class ChessGame {
    private ChessBoard board;
    private int currentPlayerIndex;
    private final List<ChessMove> moveHistory;

    public ChessGame() {
        this.board = ChessBoard.initialBoard();
        this.currentPlayerIndex = 0;
        this.moveHistory = new ArrayList<>();
    }

    // 执行走棋并返回游戏结果
    public synchronized GameResult applyMove(ChessMove move) {
        // 2. 执行走棋
        Piece capturedPiece = board.movePiece(move);
        moveHistory.add(move);

        // 4. 切换玩家
        currentPlayerIndex ^= 1; // 在0和1之间切换
        return GameResult.continueGame();
    }
}
